/**
 * 
 */
package com.james.wee.shuangseqiu.compre;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.james.wee.shuangseqiu.bo.IDBBo;
import com.james.wee.shuangseqiu.bo.OpenNumber;
import com.james.wee.shuangseqiu.db.DB;

/**
 * @author JamesWee
 * 
 */
public class Compre {
	private static boolean existsEq(OpenNumber src, OpenNumber dsc) {
		boolean flag = false;
		String[] srs = src.sixRedNum().split(",");
		String dscstr = dsc.sixRedNum();
		for (String s : srs) {
			if ((flag = dscstr.contains(s))) {
				break;
			}
		}
		return flag;
	}

	public static void contain() throws Exception {
		// java.io.BufferedWriter bw = new BufferedWriter(new FileWriter(new
		// File(
		// "C:\\Users\\JamesWee\\Desktop\\jiange.txt")));
		List<IDBBo> list = DB.getInstance()
				.queryBoList("SELECT * FROM OpenNumber   ORDER BY ID DESC",
						OpenNumber.class);
		// OpenNumber ober = new OpenNumber("2013014", "02", "03", "16", "17",
		// "24", "27", "03", null);
		// ober.setId(782);
		// list.add(0, ober);
		Map<String, String> map = new HashMap<String, String>();
		int maxid = list.get(0).getId();
		for (int i = 0,ls=list.size(); i < ls; i++) {
			OpenNumber src = (OpenNumber) list.get(i);
			map.put("" + src.getId(), src.getOpennum());
		}

		for (int j = 0, lens = 70; j < lens; j++) {
			OpenNumber src = (OpenNumber) list.get(j);
			OpenNumber dsc = null;
			List<Integer> tmpfalse = new ArrayList<Integer>();
			List<Integer> tmptrue = new ArrayList<Integer>();
			List<Integer> tmpid = new ArrayList<Integer>();
				
			for (int i = (j + 1), len = 70 + j; i < len; i++) {
				dsc = (OpenNumber) list.get(i);
				int a = 0;
				if (!existsEq(src, dsc)) {
					a = src.getId() - dsc.getId();
					tmpid.add(dsc.getId());
					tmpfalse.add(a);
					// if (!sha.contains(Integer.valueOf(dsc.getN_1())))
					// sha.add(Integer.valueOf(dsc.getN_1()));
					// if (!sha.contains(Integer.valueOf(dsc.getN_2())))
					// sha.add(Integer.valueOf(dsc.getN_2()));
					// if (!sha.contains(Integer.valueOf(dsc.getN_3())))
					// sha.add(Integer.valueOf(dsc.getN_3()));
					// if (!sha.contains(Integer.valueOf(dsc.getN_4())))
					// sha.add(Integer.valueOf(dsc.getN_4()));
					// if (!sha.contains(Integer.valueOf(dsc.getN_5())))
					// sha.add(Integer.valueOf(dsc.getN_5()));
					// if (!sha.contains(Integer.valueOf(dsc.getN_6())))
					// sha.add(Integer.valueOf(dsc.getN_6()));
				} else {
					a = src.getId() - dsc.getId();
					
					tmptrue.add(a);
				}

			}
			java.util.Collections.sort(tmpfalse);
			 String r = tmpfalse.toString();
			 String di = tmpid.toString();
			int total = 0;
//			String r = "";
//			String dou = "";
			for (Integer c : tmpfalse) {
				total += c;
//				r += dou + map.get(""+(maxid - c));
//				dou = ",";
			}
//			System.out.println(src.getOpennum() + "==> " + r + " ==>" + total);
			String up = r.substring(1, r.length() - 1).replaceAll(" ", "");
//			src.setSpacing(up);
//			DB.getInstance().updateByMethod(src, OpenNumber.class, "updateSpacing");
			 System.out.println(src.getOpennum() + "==> "
			 + up+"=="+total+"\n" );
			 
//			 System.out.println(src.getOpennum() + "==> "
//					 + di.substring(1, di.length() - 1) );
		}
		// bw.close();
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try {
			
			contain();
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
